package com.quick.develop.flowable.controller.job;

import com.quick.develop.framework.common.page.R;
import com.quick.develop.flowable.domain.job.BpmDeadJobPageReqVO;
import com.quick.develop.flowable.service.task.IBpmJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author junyuan.liu
 * @description:
 * @date 2022/9/21 9:32
 */
@Api(tags = "流程管理后台 - 流程JOB")
@RestController
@RequestMapping("/job")
@Validated
public class BpmJobController {
    @Resource
    private IBpmJobService bpmJobService;

    @GetMapping("/dead-page")
    @ApiOperation("获取 dead-job 分页")
    public R<?> getDeadJobPage(@Valid BpmDeadJobPageReqVO reqVO){
        return R.ok(bpmJobService.deadLetterPage(reqVO));
    }
    
    @PutMapping("/restore-dead/{jobId}")
    @ApiOperation("恢复死信表到运行表")
    public R<?> restoreDeadJob(@PathVariable("jobId") String id) {
        bpmJobService.restoreDeadJob(id);
        return R.ok();
    }
    
    @GetMapping("/get-dead-exception-stacktrace/{jobId}")
    @ApiOperation("死信节点异常堆栈信息")
    public R<?> getDeadExceptionStacktrace(@PathVariable("jobId") String id){
        return R.ok(bpmJobService.getDeadLetterJobExceptionStacktrace(id));
    }
}
